<template>
	<view class="root">
		<view class="cart" v-show="cart.length > 0">
			<view class="address">
				<address-com></address-com>
			</view>
			<view class="cart-box">
				<view class="cart-title">
					<uni-icons type="shop" size="18"></uni-icons>
					<text>购物车</text>
				</view>
				<view class="cart-goods-list">
					<uni-swipe-action>
						<block v-for="(goods, i) in cart" :key="i">
							<uni-swipe-action-item :right-options="options" @click="swipeActionClickHandler(goods.goods_id)">
								<goods-item @number-change="numberChangeHandler" @radio-change="radioChangeHandler" :goods="goods"
									:showRadio="true" :showNumberBox="true"></goods-item>
							</uni-swipe-action-item>
						</block>
					</uni-swipe-action>
				</view>
				<view class="cart-settle">
					<cart-settle></cart-settle>
				</view>
			</view>
		</view>
		<view class="empty-cart" v-show="cart.length === 0">
			<image src="/static/cart_empty@2x.png" mode=""></image>
			<text>空空如也~</text>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	import {
		mapMutations
	} from 'vuex'
	import {
		mapState
	} from "vuex";
	export default {
		mixins: [badgeMix],
		computed: {
			...mapState('m_cart', ['cart'])
		},
		data() {
			return {
				options: [{
					text: '删除', // 显示的文本内容
					style: {
						backgroundColor: '#C00000' // 按钮的背景颜色
					}
				}]
			};
		},
		methods: {
			...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount', 'removeCartGoodsById']),
			radioChangeHandler(e) {
				this.updateGoodsState(e, )
			},
			numberChangeHandler(e) {
				this.updateGoodsCount(e)
			},
			// 点击了滑动操作按钮
			swipeActionClickHandler(goods_id) {
			  this.removeCartGoodsById(goods_id)
			}
		}
	}
</script>

<style lang="scss">
	.cart-box {
		padding-bottom: 50px;
		.cart-title {
			height: 40px;
			line-height: 40px;
			border-bottom: 1px solid #efefef;
			text {
				margin-left: 10px;
				font-size: 14px;
			}
		}
	}
	.empty-cart{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		width: 100%;
		height: 100%;
		padding-top: 150px;
		font-size: 12px;
		color:gray;
		image {
			width: 100px;
			height: 100px;
		}
		text{
			margin-top: 10px;
		}
	}
</style>